package com.google.code.jcooky.rpc.connect;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpConnector implements Connector {
	
	private HttpURLConnection conn;
	
	
	public HttpConnector(URL url) throws IOException {
		String prot = url.getProtocol();
		if(prot.toLowerCase().equals("http") || prot.toLowerCase().equals("https"))
			conn = (HttpURLConnection)url.openConnection();
		else
			throw new IOException("http 프로토콜이 아닙니다.");
	}

	public InputStream getInputStream() throws IOException {
		synchronized(conn) {
			conn.setRequestMethod("POST");
			return conn.getInputStream();
		}
	}

	public OutputStream getOutputStream() throws IOException {
		return new HttpConnectorOutputStream(conn);
	}
}
